package com.graduation.mathematics.http;

import java.util.concurrent.TimeUnit;

import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Call;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;
import retrofit2.http.GET;
import retrofit2.http.Header;
import retrofit2.http.Headers;
import retrofit2.http.Query;

public class APIManager {
    public static final String TAG = APIManager.class.getName();
    public static final String BASE_URL = "";
    private static Retrofit retrofit;

    public static Retrofit getRetrofit(){
        if (retrofit == null) {
            HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
            logging.setLevel(HttpLoggingInterceptor.Level.BODY);
            OkHttpClient.Builder builder  = new OkHttpClient.Builder();
            builder.readTimeout(60, TimeUnit.SECONDS);
            OkHttpClient client = builder.addInterceptor(logging).build();

            retrofit = new Retrofit.Builder().baseUrl(BASE_URL)
                    .addConverterFactory(GsonConverterFactory.create())
                    .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                    .client(client)
                    .build();
        }
        return retrofit;
    }

    public interface ServerAPI{
        @Headers({"Content-Type: application/json","Accept: application/json"})
        @GET("")
        Call<ResultData<String>> getExercises(@Query("grade") String grade);
    }


}
